refactor: extract backup restore helper#176
refactor: extract backup restore helper#176ndycode wants to merge 1 commit intorefactor/pr3-storage-backup-metadata-helpersfrom
Conversation
|
Important Review skippedAuto reviews are limited based on label configuration. 🚫 Review skipped — only excluded labels are configured. (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary
lib/storage.tsinto a dedicated helper moduleWhat Changed
lib/storage/restore.tswithrestoreAccountsFromBackupFile(...)lib/storage.tssorestoreAccountsFromBackup(...)delegates to the extracted helper with injected file-system and storage dependenciesValidation
npm run test -- test/storage.test.tsnpm run lintnpm run typechecknpm run buildRisk and Rollback
a3d6bf6to restore the inline backup restore helper implementationAdditional Notes
note: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
this pr extracts the backup-restore validation and persistence logic from
lib/storage.tsinto a newlib/storage/restore.tshelper, following the same incremental storage-split pattern established in prior slices. the delegation instorage.tsis thin and correct, and all existing path-traversal safety checks (symlink resolution viarealpath,relative+isAbsoluteguard against directory escape) are preserved verbatim.key observations:
RestoreAccountsFromBackupDeps) making it unit-testable — but no dedicated isolation test file exists yet. existing coverage flows through thestorage.tswrapper + real filesystem (storage-last-backup.test.ts), leaving several error branches (non-ENOENTrealpathfailures,saveAccountsthrow, concurrent restore races) untested at the unit level. this is the main gap to address before the next slice.restore.tsimportsAccountStorageV3as a type from../storage.js, whilestorage.tsimportsrestoreAccountsFromBackupFilefrom./storage/restore.js— that's a mutual import cycle. type-only imports are safe at runtime in esm, but this pattern should be resolved (move the type tolib/types.ts) before it's repeated across additional extracted modules.realpath→relative→isAbsolutetraversal guard is sound for ntfs/unc paths sincenode:pathis windows-aware, andrealpathis injected so tests can mock it without hitting the filesystem.Confidence Score: 4/5
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["restoreAccountsFromBackup(path, options)\nlib/storage.ts"] -->|"delegates with injected deps"| B["restoreAccountsFromBackupFile(path, deps, options)\nlib/storage/restore.ts"] B --> C["deps.realpath(backupRoot)\nresolve & validate backup root exists"] C -->|ENOENT| E1["throw: Backup root does not exist"] C -->|other error| E2["rethrow"] C -->|ok| D["deps.realpath(path)\nresolve & validate backup file exists"] D -->|ENOENT| E3["throw: Backup file no longer exists"] D -->|other error| E4["rethrow"] D -->|ok| F["relative(resolvedRoot, resolvedPath)\npath traversal guard"] F -->|outside root| E5["throw: Backup path must stay inside root"] F -->|inside root| G["deps.loadAccountsFromPath(resolvedPath)\nparse backup JSON"] G -->|ENOENT| E6["throw: Backup file no longer exists"] G -->|ok| H{normalized accounts?} H -->|null or empty| E7["throw: Backup does not contain any accounts"] H -->|valid| I{persist !== false?} I -->|yes| J["deps.saveAccounts(normalized)"] I -->|no| K["return normalized"] J --> KPrompt To Fix All With AI
Last reviewed commit: "refactor: extract ba..."